<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>{{phone|formatPhone}}</h1>
        <h2>{{time|formatTime}}</h2>
    </div>
</body>
</html>
<script src="./vue-2.5.21.js"></script>
<script>
    //定义全局过滤器
    Vue.filter('formatPhone',(phone)=>{
        return phone.slice(0,3)+"***"+phone.slice(-4)
    })
    Vue.filter('formatTime',(t)=>{
        return `${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`
    })
    var v = new Vue({
        el:'#app',
        data:{
            phone:'15291695373',
            time:new Date()
        },
        filters:{//定义局部过滤器（只能在定义的位置使用）
            // formatPhone(phone){
            //     return phone.slice(0,3)+"***"+phone.slice(-4)
            // },
            // formatTime(t){
            //     return `${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`
            // }
        }
    })
</script>